package com.pllandxzx.mapper;

import com.pll.dto.ResponseDto;
import com.pll.pojo.Order;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@Mapper
public interface HomeMapper
{
    @Select("SELECT COUNT(*) FROM `order` WHERE DATE_FORMAT(end_time, '%Y-%m-%d') = #{formattedDate}")
    Integer getAllOrderData(String formattedDate);

    @Select("SELECT * FROM `order` WHERE DATE_FORMAT(end_time, '%Y-%m-%d') = #{nowAllOrderData}")
    List<Order> getTodayOrder(String formattedDate);

    Double getMerchantsDraw(long merId);

    @Select("SELECT DATE_FORMAT(end_time, '%Y-%m-%d') AS order_date, " +
            "       SUM(actual_price) AS total_amount " +
            "FROM `order` " +
            "WHERE end_time >= #{sevenDaysAgo} AND end_time < #{currentDatePlusOne} " +
            "GROUP BY DATE_FORMAT(end_time, '%Y-%m-%d') " +
            "ORDER BY order_date")
    List<Map<String, Object>> getDailyOrderAmount(
            @Param("sevenDaysAgo") LocalDate sevenDaysAgo,
            @Param("currentDatePlusOne") LocalDate currentDatePlusOne);

    @Select("SELECT status, COUNT(*) AS status_count " +
            "FROM `order` " +
            "GROUP BY status " +
            "ORDER BY status")
    List<Map<String, Object>> getOrderStatusCount();
}
